﻿
namespace SwtorCalculator.Talent {
    using System;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Media;
    using Talents;

    /// <summary>
    /// Interaction logic for TalentTab.xaml
    /// </summary>
    public partial class TalentTab : UserControl {
        private const string PREFIX = @"pack://application:,,,/SwtorCalculator;component/Images/TalentCalc/";
        private SolidColorBrush _blackBrush = new SolidColorBrush( Colors.Black );
        private SolidColorBrush _blueBrush = SystemColors.MenuHighlightBrush;
        TalentBase tal;

        internal TalentTab() : this( Character.TalentSpec ) { }
        internal TalentTab( TalentBase t ) {
            InitializeComponent();
            tal = t;
            PtsAvailable = 41;
            TreeOne.Tree = 0;
            TreeTwo.Tree = 1;
            TreeThree.Tree = 2;
            TreeOne.CharacterTalents = tal;
            TreeTabOne.Header = TreeOne.TreeName + " (" + TreeOne.Points() + ")";
            TreeTwo.CharacterTalents = tal;
            TreeTabTwo.Header = TreeTwo.TreeName + " (" + TreeTwo.Points() + ")";
            TreeThree.CharacterTalents = tal;
            TreeTabThree.Header = TreeThree.TreeName + " (" + TreeThree.Points() + ")";
            TreeOne.TalentsChanged += new EventHandler( TalentsChanged );
            TreeTwo.TalentsChanged += new EventHandler( TalentsChanged );
            TreeThree.TalentsChanged += new EventHandler( TalentsChanged );
        }

        internal static int PtsAvailable { get;  set; }

        private void setTalents() {
            TreeOne.CharacterTalents = tal;
            TreeTabOne.Header = TreeOne.TreeName + " (" + TreeOne.Points() + ")";
            TreeTwo.CharacterTalents = tal;
            TreeTabTwo.Header = TreeTwo.TreeName + " (" + TreeTwo.Points() + ")";
            TreeThree.CharacterTalents = tal;
            TreeTabThree.Header = TreeThree.TreeName + " (" + TreeThree.Points() + ")";
        }

        internal void TalentsChanged( object sender, EventArgs e ) {
            setTalents();
            TalentProgress.Value = PtsAvailable;
            RemainPoints.Content = string.Format( "Points Left : {0}", PtsAvailable );
        }

        private void Item_MouseEnter( object sender, MouseEventArgs e ) {
            ResetBtn.Foreground = _blueBrush;
            ResetBtn.BorderBrush = _blueBrush;
        }

        private void Item_MouseLeave( object sender, MouseEventArgs e ) {
            ResetBtn.Foreground = _blackBrush;
            ResetBtn.BorderBrush = _blackBrush;
        }
    }
}
